package com.example;

import com.example.mapper.Test1Mapper;
import com.example.mapper.SequenceMapper;
//import com.example.mapper.UserMapper;
import com.example.model.Test1;
//import com.example.model.User;
import org.apache.ibatis.session.SqlSession;

public class Main {
    public static void main(String[] args) {
        SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession(false); // 设置非自动提交
        try {
            // UserMapper mapper = session.getMapper(UserMapper.class);
            // User user = new User(1, "John Doe", "john.doe@example.com");
            // int updateCount;
            // int rowsAffected;

            // rowsAffected = mapper.insertUser(user);
            // session.commit();
            // updateCount = session.getConnection().createStatement().getUpdateCount();
            // System.out.println("Number of rows affected: " + updateCount +','+rowsAffected);
            
            // rowsAffected = mapper.insertUser(user);
            // session.commit();
            // updateCount = session.getConnection().createStatement().getUpdateCount();
            // System.out.println("Number of rows affected: " + updateCount +','+rowsAffected);

            // rowsAffected = mapper.insertUser(user);
            // session.commit();
            // updateCount = session.getConnection().createStatement().getUpdateCount();
            // System.out.println("Number of rows affected: " + updateCount +','+rowsAffected);

            // rowsAffected = mapper.insertUser(user);
            // session.commit();
            // updateCount = session.getConnection().createStatement().getUpdateCount();
            // System.out.println("Number of rows affected: " + updateCount +','+rowsAffected);

            // rowsAffected = mapper.insertUser(user);
            // session.commit();
            // updateCount = session.getConnection().createStatement().getUpdateCount();
            // System.out.println("Number of rows affected: " + updateCount +','+rowsAffected);

            // rowsAffected = mapper.insertUser(user);
            // session.commit();
            // updateCount = session.getConnection().createStatement().getUpdateCount();
            // System.out.println("Number of rows affected: " + updateCount +','+rowsAffected);

            // System.out.println("User inserted successfully");

            Test1Mapper mapper = session.getMapper(Test1Mapper.class);
            SequenceMapper seqmapper = session.getMapper(SequenceMapper.class);
            long sequenceno = seqmapper.getNextSequenceValue("sequenceno");;
            long transactionno=1685;
            Test1 user = new Test1( sequenceno, "SPIDER",  transactionno,"1","ADMIN","20241220","16:59:05",null,null,null,"0","ABCD","00000001","CC1234","0011","1");
            int updateCount;
            int rowsAffected;

            rowsAffected = mapper.insert(user);
            session.commit();
            updateCount = session.getConnection().createStatement().getUpdateCount();
            System.out.println("****** Number of rows affected: " + updateCount +','+rowsAffected+ "******");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }
    }
}